package com.jg.service.impl;

import com.jg.comm.Page;
import com.jg.entity.Book;
import com.jg.mapper.BookMapper;
import com.jg.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 86130
 * @version 1.0
 * @description: TODO
 * @date 2025/9/1 下午2:48
 */
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    BookMapper bookMapper;

    @Override
    public Page<Book> getBookPage(String bookName, String author, Integer pageNum, Integer pageSize) {
        Page<Book> page = new Page<>();
        page.setPageNum(pageNum);
        page.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = bookMapper.getBookListTotalCount(bookName, author);
        page.setTotalCount(totalCount);

        page.setData(bookMapper.getBookListPage(bookName, author, (pageNum-1)*pageSize, pageSize));
        return page;
    }

    @Override
    public String addBook(Book book) {
        return bookMapper.addBook(book) > 0 ? "success" : "fail";
    }

    @Override
    public String deleteBook(Integer id) {
        return bookMapper.deleteBook(id) > 0 ? "success" : "fail";
    }

    @Override
    public String updateBook(Book book) {
        return bookMapper.updateBook(book) > 0 ? "success" : "fail";
    }
}
